package cn.wuyi.common.thread;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 * @类功能说明:   spring 线程池
 * @作者                ：
 * @版本                ：V1.0
 */
@Configuration
public class ThreadPoolTaskExecutorBean {
	
	@Bean
	public ThreadPoolTaskExecutor threadPoolTaskExecutor() {
		ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();
		//线程池维护线程的最少数量:默认5个
		int corePoolSize =5;
		//线程池维护线程的最大数量:默认20
		int maxPoolSize =20;
		//线程池维护线程所允许的空闲时间:默认300秒
		int keepAliveSeconds = 300;
		//线程池所使用的缓冲队列:默认25
		int queueCapacity = 200;
		threadPoolTaskExecutor.setCorePoolSize(corePoolSize);
		threadPoolTaskExecutor.setMaxPoolSize(maxPoolSize);
		threadPoolTaskExecutor.setKeepAliveSeconds(keepAliveSeconds);
		threadPoolTaskExecutor.setQueueCapacity(queueCapacity);
		threadPoolTaskExecutor.initialize();
        return threadPoolTaskExecutor;
	}
	
}
